package com.afs.electronicforensics.fragment;

import android.os.Bundle;
import android.os.Environment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.afs.electronicforensics.activity.R;
import com.afs.electronicforensics.adapter.VideoLocalAdapter;
import com.afs.electronicforensics.entity.FileInfo;
import com.afs.electronicforensics.utils.Constants;

import java.io.File;
import java.util.ArrayList;

public class VideoLocalFragment extends Fragment {@Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        ViewGroup root = (ViewGroup) inflater.inflate(R.layout.recyclerview_card, container, false);

        ArrayList<FileInfo> items = new ArrayList<>();
        String path = Environment.getExternalStorageDirectory().getAbsolutePath()+ Constants.USER_PATH.getVideoPath();
        File filepath = new File(path);
        File[] files = filepath.listFiles();

        if (null != files) {
            for (int i = 0; i < files.length; i++) {
                String fileName = files[i].getName();
                items.add(new FileInfo(fileName,path+fileName));
            }
        }

        RecyclerView recyclerView = root.findViewById(R.id.recyclerview_card);
        StaggeredGridLayoutManager layoutManager=new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);
        VideoLocalAdapter adapter =new VideoLocalAdapter(getContext(),items);
        recyclerView.setAdapter(adapter);

        return root;
    }
}
